//********************************************************************
// 
//  file:  AccountManagement.cs
// 
//  (C) Copyright 2010, Diomede Corporation
//  All rights reserved
// 
//  Use, modification, and distribution is subject to   
//  the New BSD License (See accompanying file license.txt).
// 
//********************************************************************

using System;
using System.Collections.Generic;

using data.diomedestorage.com;

namespace Diomede.SDK
{

    #region Interfaces
    /// <summary>
    /// Provide the interface for handling Diomede Accounts
    /// </summary>
    public interface IAccountManagement
    {
        /// <summary>
        /// Create new Diomede Account
        /// </summary>
        /// <param name="username">User Name</param>
        /// <param name="password">Password</param>
        /// <param name="email">Email</param>
        /// <returns>Will return Session Execution Result, see <see cref="ISessionExecResult"/>.</returns>
        /// <example>
        /// <code>
        /// static void CreateAccountSample()
        /// {
        ///     ISession session = new Session();
        ///     IAccountManagement accountManager = session as IAccountManagement;
        ///     if (accountManager.Create(username, password, email).Status != ExecutionResults.Success)
        ///     {
        ///         throw new Exception("Fails to create account.");
        ///     }
        ///     else
        ///     {
        ///         Console.WriteLine("Account successfully created.");
        ///     }
        /// }
        /// 
        /// </code>
        /// <code lang="VB.NET">
        /// Shared Sub CreateAccountSample()
        ///    Dim session As ISession = New Session()
        ///    Dim accountManager As IAccountManagement = CType(session, IAccountManagement)
        ///
        ///    If accountManager.Create(username, password, email).Status &lt;&gt; ExecutionResults.Success Then
        ///        Throw New Exception("Fails to create account.")
        ///    Else
        ///        Console.WriteLine("Account successfully created.")
        ///    End If
        /// End Sub
        /// </code>
        /// </example>
        ISessionExecResult Create(string username, string password, string email);
        
        /// <summary>
        /// Update the account information of currently login user.
        /// </summary>
        /// <param name="accountInfo">Modified account information</param>
        /// <returns>Will return Session Execution Result, see <see cref="ISessionExecResult"/>.</returns>
        /// <example>
        /// <code>
        /// static void SetAccountInfoSample()
        /// {
        ///     ISession session = new Session();
        ///     if (session.Login(username, password).Status != ExecutionResults.Success)
        ///     {
        ///         throw new Exception("Fail to login.");
        ///     }
        /// 
        ///     IAccountManagement accountManager = session as IAccountManagement;
        ///     //create userinfo
        ///     UserInfo userInfo = new UserInfo();
        ///     userInfo.firstName = "Melvin";
        ///     userInfo.lastName = "Sembrano";
        ///     userInfo.companyName = "MS Company";
        ///     userInfo.websiteUrl = "www.melvin.com";
        ///     userInfo.cardName = "AMelvin Sembrano";
        ///     userInfo.cardNumber = "1234567890123456";
        ///     userInfo.cardCvv2 = "023";
        ///     userInfo.cardAddress1 = "123 Address 1-A";
        ///     userInfo.cardAddress2 = "321 Address 2-B";
        ///     userInfo.cardCity = "Cebu";
        ///     userInfo.cardState = "Cebu P";
        ///     userInfo.cardCountry = "63";
        ///     userInfo.cardZip = "6000";
        /// 
        ///     if (accountManager.UpdateAccountInfo(userInfo).Status != ExecutionResults.Success)
        ///     {
        ///         throw new Exception("Fails to update account information.");
        ///     }
        ///     else
        ///     {
        ///         Console.WriteLine("Successfully update the user info.");
        ///     }
        /// 
        ///     session.Logout();
        /// }
        /// 
        /// </code>
        /// <code lang="VB.NET">
        /// Shared Sub SetAccountInfoSample()
        ///    Dim session As ISession = New Session()
        ///    If session.Login(username, password).Status &lt;&gt; ExecutionResults.Success Then
        ///        Throw New Exception("Fails to login.")
        ///    End If
        ///
        ///    Dim accountManager As IAccountManagement = CType(session, IAccountManagement)
        ///
        ///    'create userinfo
        ///    Dim userInfo As New UserInfo
        ///    userInfo.firstName = "Melvin"
        ///    userInfo.lastName = "Sembrano"
        ///    userInfo.companyName = "MS Company"
        ///    userInfo.websiteUrl = "www.melvin.com"
        ///    userInfo.cardName = "AMelvin Sembrano"
        ///    userInfo.cardNumber = "1234567890123456"
        ///    userInfo.cardCvv2 = "023"
        ///    userInfo.cardAddress1 = "123 Address 1-A"
        ///    userInfo.cardAddress2 = "321 Address 2-B"
        ///    userInfo.cardCity = "Cebu"
        ///    userInfo.cardState = "Cebu P"
        ///    userInfo.cardCountry = "63"
        ///    userInfo.cardZip = "6000"
        ///
        ///    If accountManager.UpdateAccountInfo(userInfo).Status &lt;&gt; ExecutionResults.Success Then
        ///        Throw New Exception("Fails to update account information.")
        ///    Else
        ///        Console.WriteLine("Successfully update the user info.")
        ///    End If
        ///    session.Logout()
        /// End Sub
        /// </code>
        /// </example>
        ISessionExecResult UpdateAccountInfo(UserInfo accountInfo);

        /// <summary>
        /// Delete the current user's account information.
        /// </summary>
        /// <param name="type">The user information type to be deleted.  If UserInfoType.UserInfo, will delete account's FirstName, LastName, CompanyName and WebsiteUrl.  If UserInfoType.BillingInfo, will delete account's billing information.
        /// </param>
        /// <returns>Will return Session Execution Result, see <see cref="ISessionExecResult"/>.</returns>
        /// <example>
        /// <code>
        /// static void DeleteAccountInfoSample()
        /// {
        ///     ISession session = new Session();
        ///     if (session.Login(username, password).Status != ExecutionResults.Success)
        ///     {
        ///         throw new Exception("Fail to login.");
        ///     }
        /// 
        ///     IAccountManagement accountManager = session as IAccountManagement;
        ///     //delete the current billing info
        ///     if (accountManager.DeleteAccountInfo(UserInfoType.BillingInfo).Status != ExecutionResults.Success)
        ///     {
        ///         throw new Exception("Fail to delete billing information.");
        ///     }
        ///     else
        ///     {
        ///         Console.WriteLine("Successfully deleted the account billing information.");
        ///     }
        /// }
        /// 
        /// </code>
        /// <code lang="VB.NET">
        /// Shared Sub DeleteAccountInfoSample()
        ///    Dim session As ISession = New Session
        ///    If session.Login(username, password).Status &lt;&gt; ExecutionResults.Success Then
        ///        Throw New Exception("Fails to login.")
        ///    End If
        ///
        ///    Dim accountManager As IAccountManagement = CType(session, IAccountManagement)
        ///
        ///    'delete the current billing info
        ///    If accountManager.DeleteAccountInfo(UserInfoType.allBillingInfo).Status &lt;&gt; ExecutionResults.Success Then
        ///        Throw New Exception("Fail to delete billing information.")
        ///    Else
        ///        Console.WriteLine("Successfully deleted the account billing information.")
        ///    End If
        /// End Sub
        /// </code>
        /// </example>
        ISessionExecResult DeleteAccountInfo(UserInfoType type);
        
        /// <summary>
        /// Update the account information of currently login user.
        /// </summary>
        /// <param name="companyName">Company name</param>
        /// <param name="lastName">Last name</param>
        /// <param name="firstName">First name</param>
        /// <param name="telephone">Telephone #</param>
        /// <param name="websiteUrl">Website url</param>
        /// <returns>Will return Session Execution Result, see <see cref="ISessionExecResult"/>.</returns>
        /// <example>
        /// <code>
        /// static void updateAccount()
        /// {
        ///     ISession session = new Session();
        ///     IAccountManagement accountMgr = session as IAccountManagement;
        ///     ISessionExecResult result = accountMgr.Update("username", "password", "myaddress@email.com", "My Company Name", "LastName", "FirstName", "123-1234567");
        ///     if (result.Status == ExecutionResults.Success)
        ///         Console.WriteLine(string.Format("Account succesfully updated."));
        ///     else
        ///         Console.WriteLine(string.Format("Failed to update account information, error: {0}", result.Message));
        /// }
        /// </code>
        /// <code lang="VB.NET">
        /// Sub UpdateAccount()
        ///     Dim session As ISession = New Session()
        ///     Dim accountMgr As IAccountManagement = session
        ///     'execute create account
        ///     Dim result As ISessionExecResult = accountMgr.Update("username", "password", "myaddress@email.com", "My Company Name", "LastName", "FirstName", "123-1234567")
        ///     If (result.Status = Enums.ExecutionResults.Success) Then
        ///         Console.WriteLine(String.Format("Account successfully updated."))
        ///     Else
        ///         Console.WriteLine(String.Format("Failed to update account information, error: {0}", result.Message))
        ///     End If
        /// End Sub
        /// </code>
        /// </example>
        ISessionExecResult UpdateAccountInfo(string lastName, string firstName, string companyName, string websiteUrl, string telephone);
        
        /// <summary>
        /// Delete the current login account.
        /// </summary>
        /// <returns>Will return Session Execution Result, see <see cref="ISessionExecResult"/>.</returns>
        /// <example>
        /// <code>
        ///     ISession session = new Session();
        ///     ISessionExecResult result;
        ///     //login to Diomede Services
        ///     result = session.Login("username", "password");
        ///     if (result.Status != ExecutionResults.Success)
        ///     {
        ///         Console.WriteLine(string.Format("Fail to login, error: {0}", result.Message));
        ///         return;
        ///     }
        /// 
        ///     IAccountManagement accountMgr = session as IAccountManagement;
        ///     result = accountMgr.Delete();
        ///     if (result.Status == ExecutionResults.Success)
        ///         Console.WriteLine(string.Format("Account succesfully deleted."));
        ///     else
        ///         Console.WriteLine(string.Format("Failed to delete account, error: {0}", result.Message));
        /// 
        /// </code>
        /// <code lang="VB.NET">
        /// Dim session As ISession = New Session()
        /// Dim result As ISessionExecResult
        /// 
        /// 'login to Diomede Services
        /// result = session.Login("username", "password")
        /// If Not (result.Status = Enums.ExecutionResults.Success) Then
        ///     Console.WriteLine(String.Format("Fail to login, error: {0}", result.Message))
        ///     Return
        /// End If
        /// 
        /// Dim accountMgr As IAccountManagement = session
        /// result = accountMgr.Delete()
        /// 
        /// If (result.Status = Enums.ExecutionResults.Success) Then
        ///     Console.WriteLine(String.Format("Account successfully deleted."))
        /// Else
        ///     Console.WriteLine(String.Format("Failed to delete account, error: {0}", result.Message))
        /// End If
        /// </code>
        /// </example>
        ISessionExecResult Delete();
        
        /// <summary>
        /// Get user's account information.
        /// </summary>
        /// <returns>Will return ISessionExecResult.Status == Success if execution is successful, see <see cref="ISessionExecResult"/>.</returns>
        /// <example>
        /// <code>
        /// static void GetAccountInfoSample()
        /// {
        ///     ISession session = new Session();
        ///     if (session.Login(username, password).Status != ExecutionResults.Success)
        ///     {
        ///         throw new Exception("Fail to login.");
        ///     }
        /// 
        ///     IAccountManagement accountManager = session as IAccountManagement;
        /// 
        ///     ISessionExecResult result = accountManager.GetAccountInfo();
        ///     if (result.Status != ExecutionResults.Success)
        ///     {
        ///         throw new Exception("Fails to get user's account information.");
        ///     }
        ///     UserInfo userInfo = result.UserInfo;
        ///     Console.WriteLine(string.Format("{0} {1}'s information.",userInfo.firstName, userInfo.lastName));
        /// }
        /// </code>
        /// <code lang="VB.NET">
        /// Shared Sub GetAccountInfoSample()
        ///    Dim session As ISession = New Session()
        ///    If session.Login(username, password).Status &lt;&gt; ExecutionResults.Success Then
        ///        Throw New Exception("Fails to login.")
        ///    End If
        ///
        ///    Dim accountManager As IAccountManagement = CType(session, IAccountManagement)
        ///
        ///    Dim result As ISessionExecResult = accountManager.GetAccountInfo()
        ///    If result.Status &lt;&gt; ExecutionResults.Success Then
        ///        Throw New Exception("Fails to get user's account information.")
        ///    End If
        ///
        ///    Dim userInfo As UserInfo = result.UserInfo
        ///    Console.WriteLine(String.Format("{0} {1}'s information.", userInfo.firstName, userInfo.lastName))
        /// End Sub
        /// </code>
        /// </example>
        ISessionExecResult GetAccountInfo();

        /// <summary>
        /// Add new email address to the account.
        /// </summary>
        /// <param name="email">Email address to add.</param>
        /// <returns>Will return Session Execution Result, see <see cref="ISessionExecResult"/>.</returns>
        /// <example>
        /// <code>
        /// static void AddEmailAddressSample()
        /// {
        ///     ISession session = new Session();
        ///     if (session.Login(username, password).Status != ExecutionResults.Success)
        ///     {
        ///         throw new Exception("Fails to login.");
        ///     }
        /// 
        ///     IAccountManagement accountManager = session as IAccountManagement;
        /// 
        ///     if (accountManager.AddEmail(string.Format("{0}_second@sample.com", username)).Status != ExecutionResults.Success)
        ///     {
        ///         throw new Exception("Fails to add email address.");
        ///     }
        ///     else
        ///     {
        ///         Console.WriteLine("Successfully added email address.");
        ///     }
        /// }
        /// </code>
        /// <code lang="VB.NET">
        /// Shared Sub AddEmailAddressSample()
        ///    Dim session As ISession = New Session()
        ///    If session.Login(username, password).Status &lt;&gt; ExecutionResults.Success Then
        ///        Throw New Exception("Fails to login.")
        ///    End If
        ///
        ///    Dim accountManager As IAccountManagement = CType(session, IAccountManagement)
        ///
        ///    If accountManager.AddEmail(String.Format("{0}_second@sample.com", username)).Status &lt;&gt; ExecutionResults.Success Then
        ///        Throw New Exception("Fails to add email address.")
        ///    Else
        ///        Console.WriteLine("Successfully added email address.")
        ///    End If
        /// End Sub
        /// </code>
        /// </example>
        ISessionExecResult AddEmail(string email);

        /// <summary>
        /// Get the email addresses of the current account
        /// </summary>
        /// <returns>Will return EmailExecResult.Status == Success if command is successfully executed and stored the addresses it to Emails property.  See <see cref="EmailsExecResult"/> for more information.</returns>
        /// <example>
        /// <code>
        /// static void GetEmailAddressSample()
        /// {
        ///    ISession session = new Session();
        ///    if (session.Login(username, password).Status != ExecutionResults.Success)
        ///    {
        ///        throw new Exception("Fails to login.");
        ///    }
        ///
        ///    IAccountManagement accountManager = session as IAccountManagement;
        ///
        ///    if (accountManager.GetEmailAddresses().Status != ExecutionResults.Success)
        ///    {
        ///        throw new Exception("Fails to retrieve email addresses.");
        ///    }
        ///    else
        ///    {
        ///        Console.WriteLine("Successfully retrieved email addresses.");
        ///    }
        /// }
        /// </code>
        /// <code lang="VB.NET">
        /// Private Shared Sub GetEmailAddressSample()
        ///     Dim session As ISession = New Session()
        ///     If session.Login(username, password).Status &lt;&gt; ExecutionResults.Success Then
        ///         Throw New Exception("Fails to login.")
        ///     End If
        /// 
        ///     Dim accountManager As IAccountManagement = TryCast(session, IAccountManagement)
        /// 
        ///     If accountManager.GetEmailAddresses().Status &lt;&gt; ExecutionResults.Success Then
        ///         Throw New Exception("Fails to retrieve email addresses.")
        ///     Else
        ///         Console.WriteLine("Successfully retrieved email addresses.")
        ///     End If
        /// End Sub
        /// </code>
        /// </example>
        IEmailsExecResult GetEmailAddresses();

        /// <summary>
        /// Get the email address list of the current account.
        /// </summary>
        /// <returns>Will return list of emails if command is successfully executed, and return null otherwise.</returns>
        /// <example>
        /// <code>
        ///  static void GetEmailAddressListSample()
        /// {
        ///     ISession session = new Session();
        ///     if (session.Login(username, password).Status != ExecutionResults.Success)
        ///     {
        ///         throw new Exception("Fails to login.");
        ///     }
        /// 
        ///     IAccountManagement accountManager = session as IAccountManagement;
        /// 
        ///     if (accountManager.GetEmailAddressList() == null)
        ///     {
        ///         throw new Exception("Fails to retrieve email addresses list.");
        ///     }
        ///     else
        ///     {
        ///         Console.WriteLine("Successfully retrieved email addresses list.");
        ///     }
        /// }
        /// </code>
        /// <code lang="VB.NET">
        /// Private Shared Sub GetEmailAddressListSample()
        ///     Dim session As ISession = New Session()
        ///     If session.Login(username, password).Status &lt;&gt; ExecutionResults.Success Then
        ///         Throw New Exception("Fails to login.")
        ///     End If
        /// 
        ///     Dim accountManager As IAccountManagement = TryCast(session, IAccountManagement)
        /// 
        ///     If accountManager.GetEmailAddressList() Is Nothing Then
        ///         Throw New Exception("Fails to retrieve email addresses list.")
        ///     Else
        ///         Console.WriteLine("Successfully retrieved email addresses list.")
        ///     End If
        /// End Sub
        /// </code>
        /// </example>
        List<string> GetEmailAddressList();

        /// <summary>
        /// Remove the specified email address to the user account.
        /// </summary>
        /// <param name="email">The email address to be remove.</param>
        /// <returns>Will return EmailExecResult.Status == Success if command is successfully executed.  See <see cref="EmailsExecResult"/> for more information.</returns>
        /// <example>
        /// <code>
        /// static void RemoveEmailAddressSample()
        /// {
        ///    ISession session = new Session();
        ///    if (session.Login(username, password).Status != ExecutionResults.Success)
        ///    {
        ///        throw new Exception("Fails to login.");
        ///    }
        ///
        ///    IAccountManagement accountManager = session as IAccountManagement;
        ///
        ///    if (accountManager.RemoveEmailAddress(string.Format("{0}_second@sample.com", username)).Status != ExecutionResults.Success)
        ///    {
        ///        throw new Exception("Fails to remove email address.");
        ///    }
        ///    else
        ///    {
        ///        Console.WriteLine("Successfully removed email address.");
        ///    }
        /// }
        /// </code>
        /// <code lang="VB.NET">
        /// Private Shared Sub RemoveEmailAddressSample()
        ///     Dim session As ISession = New Session()
        ///     If session.Login(username, password).Status &lt;&gt; ExecutionResults.Success Then
        ///         Throw New Exception("Fails to login.")
        ///     End If
        /// 
        ///     Dim accountManager As IAccountManagement = TryCast(session, IAccountManagement)
        /// 
        ///     If accountManager.RemoveEmailAddress(String.Format("{0}_second@sample.com", username)).Status &lt;&gt; ExecutionResults.Success Then
        ///         Throw New Exception("Fails to remove email address.")
        ///     Else
        ///         Console.WriteLine("Successfully removed email address.")
        ///     End If
        /// End Sub
        /// </code>
        /// </example>
        IEmailsExecResult RemoveEmailAddress(string email);

        /// <summary>
        /// Set the account primary email to the specified email address.
        /// </summary>
        /// <param name="email">The email address to be set as primary.</param>
        /// <returns>Will return EmailExecResult.Status == Success if command is successfully executed.  See <see cref="EmailsExecResult"/> for more information.</returns>
        /// <example>
        ///<code>
        /// static void SetPrimaryEmailAddressSample()
        /// {
        ///    ISession session = new Session();
        ///    if (session.Login(username, password).Status != ExecutionResults.Success)
        ///    {
        ///        throw new Exception("Fails to login.");
        ///    }
        ///
        ///    IAccountManagement accountManager = session as IAccountManagement;
        ///
        ///    if (accountManager.AddEmail(string.Format("{0}_newprimary@sample.com", username)).Status != ExecutionResults.Success)
        ///    {
        ///        throw new Exception("Fails to set new primary email address.");
        ///    }
        ///    else
        ///    {
        ///        Console.WriteLine("Successfully set primary email address.");
        ///    }
        /// }
        /// </code>
        /// <code lang="VB.NET">
        /// Shared Sub SetPrimaryEmailAddressSample()
        ///    Dim session As ISession = New Session()
        ///    If session.Login(username, password).Status &lt;&gt; ExecutionResults.Success Then
        ///        Throw New Exception("Fails to login.")
        ///    End If
        ///
        ///    Dim accountManager As IAccountManagement = CType(session, IAccountManagement)
        ///
        ///    If accountManager.AddEmail(String.Format("{0}_newprimary@sample.com", username)).Status &lt;&gt; ExecutionResults.Success Then
        ///        Throw New Exception("Fails to set new primary email address.")
        ///    Else
        ///        Console.WriteLine("Successfully set primary email address.")
        ///    End If
        ///End Sub
        /// </code>
        ///</example>
        IEmailsExecResult SetPrimaryEmailAddress(string email);

        /// <summary>
        /// Search for login logs
        /// </summary>
        /// <param name="filter">Search filter</param>
        /// <returns>Will return ISearchLoginLogsExecResult.Status == Success if command is successfully executed.  See <see cref="ISearchLoginLogsExecResult"/> for more information.</returns>
        /// <example>
        /// <code>
        /// static void SearchLoginLogs()
        /// {
        ///    ISession session = new Session();
        ///    if (session.Login(username, password).Status != ExecutionResults.Success)
        ///    {
        ///        throw new Exception("Fails to login.");
        ///    }
        ///
        ///    IAccountManagement accountManager = session as IAccountManagement;
        ///
        ///    if (accountManager.SearchLoginLogs(new SearchLoginFilter()).Status != ExecutionResults.Success)
        ///    {
        ///        throw new Exception("Search on login logs fails.");
        ///    }
        ///    else
        ///    {
        ///        Console.WriteLine("Search on login logs successful.");
        ///    }
        /// }
        /// </code>
        /// <code lang="VB.NET">
        /// Private Shared Sub SearchLoginLogs()
        ///     Dim session As ISession = New Session()
        ///     If session.Login(username, password).Status &lt;&gt; ExecutionResults.Success Then
        ///         Throw New Exception("Fails to login.")
        ///     End If
        /// 
        ///     Dim accountManager As IAccountManagement = TryCast(session, IAccountManagement)
        /// 
        ///     If accountManager.SearchLoginLogs(New SearchLoginFilter()).Status &lt;&gt; ExecutionResults.Success Then
        ///         Throw New Exception("Search on login logs fails.")
        ///     Else
        ///         Console.WriteLine("Search on login logs successful.")
        ///     End If
        /// End Sub
        /// </code>
        /// </example>
        
    }

    

    #endregion

    #region Implementation

    /// <summary>
    /// AccountManagement implementation, see <see cref="IAccountManagement"/> for more information.
    /// </summary>
    public partial class Session : IAccountManagement
    {
        #region IAccountManagement Members
        
        /// <summary>
        /// IAccountManagement.Create implementation, see <see cref="IAccountManagement.Create(string, string, string)">IAccountManagement.Create</see> for more information.
        /// </summary>
        /// <param name="username">Username</param>
        /// <param name="password">Password</param>
        /// <param name="email">Email</param>
        /// <returns>Will return Session Execution Result, see <see cref="ISessionExecResult"/>.</returns>
        ISessionExecResult IAccountManagement.Create(string username, string password, string email)
        {
            if (service == null)
                service = new DiomedeStorageClient();

            try
            {
                service.CreateUser(username, password, email);
                return new SessionExecResult(Diomede.SDK.Enums.ExecutionResults.Success, "Account created successfully.");
            }
            catch (Exception ex)
            {
                return new SessionExecResult(ex);
            }
        }
        /// <summary>
        /// IAccountManagement.Update implementation, see <see cref="IAccountManagement.UpdateAccountInfo(UserInfo)">IAccountManagement.Update</see> for more information.
        /// </summary>
        /// <param name="accountInfo">Account information</param>
        /// <returns>Will return Session Execution Result, see <see cref="ISessionExecResult"/>.</returns>
        ISessionExecResult IAccountManagement.UpdateAccountInfo(UserInfo accountInfo)
        {
            if (service == null || string.IsNullOrEmpty(token))
                return new SessionExecResult(Diomede.SDK.Enums.ExecutionResults.Failed, "No active account to modify.");

            try
            {
                service.SetUserInfo(token, accountInfo);
                return new SessionExecResult(Enums.ExecutionResults.Success, "Account updated successfully.");
            }
            catch (Exception ex)
            {
                return new SessionExecResult(ex);
            }
        }
        /// <summary>
        /// IAccountManagement.DeleteAccountInfo implementation, see <see cref="IAccountManagement.DeleteAccountInfo(UserInfoType)"/> for more information.
        /// </summary>
        /// <param name="type">The type of user info to be deleted</param>
        /// <returns>Will return Session Execution Result, see <see cref="ISessionExecResult"/>.</returns>
        ISessionExecResult IAccountManagement.DeleteAccountInfo(UserInfoType type)
        {
            if (service == null || string.IsNullOrEmpty(token))
                return new SessionExecResult(Diomede.SDK.Enums.ExecutionResults.Failed, "No active account to modify.");

            try
            {
                service.DeleteUserInfo(token, type);
                return new SessionExecResult(Enums.ExecutionResults.Success, "User account deleted successfully.");
            }
            catch (Exception ex)
            {
                return new SessionExecResult(ex);
            }
        }

        /// <summary>
        /// IAccountManagement.Delete implementation, see <see cref="IAccountManagement.Delete">IAccountManagement.Delete</see> for more information.
        /// </summary>
        /// <returns>Will return Session Execution Result, see <see cref="ISessionExecResult"/>.</returns>
        ISessionExecResult IAccountManagement.Delete()
        {
            if (service == null || string.IsNullOrEmpty(token))
                return new SessionExecResult(Enums.ExecutionResults.Failed, "No active user.");

            try
            {
                service.DeleteUser(token);
                return new SessionExecResult(Diomede.SDK.Enums.ExecutionResults.Success, "Account successfully deleted.");
            }
            catch (Exception ex)
            {
                return new SessionExecResult(ex);
            }
        }
        /// <summary>
        /// IAccountManagement.GetAccountInfo implementation, see <see cref="IAccountManagement.GetAccountInfo">IAccountManagement.GetAccountInfo</see> for more information.
        /// </summary>
        /// <returns>Will return Session Execution Result, see <see cref="ISessionExecResult"/>.</returns>
        ISessionExecResult IAccountManagement.GetAccountInfo()
        {
            if (service == null || string.IsNullOrEmpty(token))
                return new SessionExecResult(Diomede.SDK.Enums.ExecutionResults.Failed, "No active user.");
            try
            {
                UserInfo profile = service.GetUserInfo(token);
                return new SessionExecResult(profile);
            }
            catch (Exception ex)
            {
                return new SessionExecResult(ex);
            }
        }

        /// <summary>
        /// IAccountManagement.AddEmail implementation, see <see cref="IAccountManagement.AddEmail(string)"/> for more information.
        /// </summary>
        /// <param name="email">Email address to add.</param>
        /// <returns>Will return Session Execution Result, see <see cref="ISessionExecResult"/>.</returns>
        ISessionExecResult IAccountManagement.AddEmail(string email)
        {
            if (service == null || string.IsNullOrEmpty(token))
                return new SessionExecResult(Enums.ExecutionResults.Failed, "No active user.");

            try
            {
                service.AddEmailAddress(token, email);
                return new SessionExecResult(Diomede.SDK.Enums.ExecutionResults.Success, "Email added successfully.");
            }
            catch (Exception ex)
            {
                return new SessionExecResult(ex);
            }
        }
        /// <summary>
        /// IAccountManagement.GetEmailAddresses implementation, see <see cref="IAccountManagement.GetEmailAddresses"/> for more information.
        /// </summary>
        /// <returns>Will return EmailsExecResult.Status if execution successful.</returns>
        IEmailsExecResult IAccountManagement.GetEmailAddresses()
        {
            if (service == null || string.IsNullOrEmpty(token))
                return new EmailsExecResult(Enums.ExecutionResults.Failed, "No active user.", null);

            try
            {
                string[] emails = service.GetEmailAddresses(token);
                
                return new EmailsExecResult(Diomede.SDK.Enums.ExecutionResults.Success, "Email added successfully.",emails);
            }
            catch (Exception ex)
            {
                return new EmailsExecResult(ex);
            }
        }

        /// <summary>
        /// IAccountManagement.GetEmailAddressList implementation, see <see cref="IAccountManagement.GetEmailAddressList"/> for more information.
        /// </summary>
        /// <returns>Will return List of emails.</returns>
        List<string> IAccountManagement.GetEmailAddressList()
        {
            IEmailsExecResult result = (this as IAccountManagement).GetEmailAddresses();
            if (result.Status == Diomede.SDK.Enums.ExecutionResults.Success)
            {
                return (result as IEmailsExecResult).Emails;
            }
            else
                return null;
        }

        /// <summary>
        /// IAccountManagement.RemoveEmailAddress implementation, see <see cref="IAccountManagement.RemoveEmailAddress(string)"/> for more information.
        /// </summary>
        /// <param name="email">Email address.</param>
        /// <returns>Will return EmailsExecResult.Status if execution successful.</returns>
        IEmailsExecResult IAccountManagement.RemoveEmailAddress(string email)
        {
            if (service == null || string.IsNullOrEmpty(token))
                return new EmailsExecResult(Enums.ExecutionResults.Failed, "No active user.", null);

            try
            {
                service.DeleteEmailAddress(token, email);
                return new EmailsExecResult(Diomede.SDK.Enums.ExecutionResults.Success, "Email successfully removed.",null);
            }
            catch (Exception ex)
            {
                return new EmailsExecResult(ex);
            }
        }

        /// <summary>
        /// IAccountManagement.SetPrimaryEmailAddress implementation, see <see cref="IAccountManagement.SetPrimaryEmailAddress(string)"/> for more information.
        /// </summary>
        /// <param name="email">Email to be set as primary.</param>
        /// <returns>Will return EmailsExecResult.Status if execution successful.</returns>
        IEmailsExecResult IAccountManagement.SetPrimaryEmailAddress(string email)
        {
            if (service == null || string.IsNullOrEmpty(token))
                return new EmailsExecResult(Enums.ExecutionResults.Failed, "No active user.", null);

            try
            {
                service.SetPrimaryEmailAddress(token, email);
                return new EmailsExecResult(Diomede.SDK.Enums.ExecutionResults.Success, "Primary email successfully set.", null);
            }
            catch (Exception ex)
            {
                return new EmailsExecResult(ex);
            }
        }
        

        #endregion

        #region IAccountManagement Members

        /// <summary>
        /// IAccountManagement.Update implementation, see <see cref="IAccountManagement.UpdateAccountInfo(string, string, string, string, string)">IAccountManagement.Update</see> for more information.
        /// </summary>
        /// <param name="lastName">Last name</param>
        /// <param name="firstName">First name</param>
        /// <param name="companyName">Company name</param>
        /// <param name="websiteUrl">Company website.</param>
        /// <param name="telephone">Phone #</param>
        /// <returns>Will return Session Execution Result, see <see cref="ISessionExecResult"/></returns>
        ISessionExecResult IAccountManagement.UpdateAccountInfo(string lastName, string firstName, string companyName, string websiteUrl, string telephone)
        {
            UserInfo accountInfo = new UserInfo();
            accountInfo.companyName = companyName;
            accountInfo.websiteUrl = websiteUrl;
            accountInfo.lastName = lastName;
            accountInfo.firstName = firstName;
            accountInfo.phone = telephone;
            return (this as IAccountManagement).UpdateAccountInfo(accountInfo);
        }

        #endregion
    }

    

    #endregion

}
